package com.moyun.controller.org;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.moyun.common.annotation.OperLog;
import com.moyun.common.aspect.BusinessType;
import com.moyun.controller.common.CommonController;
import com.moyun.model.common.PageDTO;
import com.moyun.model.common.PageParam;
import com.moyun.model.common.PageResult;
import com.moyun.model.common.R;
import com.moyun.model.po.org.SysOrgRoleEntity;
import com.moyun.service.org.SysOrgRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yangboxuan
 * @since 2021-06-01
 */
@Api(tags = "角色")
@RestController
@RequestMapping("/org/sys-org-role")
public class SysOrgRoleController extends CommonController<Object, SysOrgRoleEntity, Object, String> {
    @Autowired
    private SysOrgRoleService sysOrgRoleEntityService;

    /**
     * @return com.moyun.common.web.JsonResult
     * @Author yangboxuan
     * @Description 分页查询
     * @Date 2021-06-01
     * @Param [page]
     **/
    @ApiOperation("分页查询")
    @PostMapping("/select-condition")
    @OperLog(operModul = "角色模块", operType = BusinessType.QUERY, operDesc = "分页查询")
    public R selectCondition(@RequestBody PageParam<SysOrgRoleEntity> params) {
        PageDTO pageParams = params.getPageParams();
        Page<SysOrgRoleEntity> page = new Page<>(pageParams.getCurrent(), pageParams.getSize());
        // 获取前端传递过来的实体类对象
        SysOrgRoleEntity sysOrgRoleEntity = params.getEntityParams();
        QueryWrapper<SysOrgRoleEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(sysOrgRoleEntity.getLevelId() != null, "level_id", sysOrgRoleEntity.getLevelId());
        queryWrapper.eq(sysOrgRoleEntity.getType() != null, "type", sysOrgRoleEntity.getType());
        queryWrapper.orderByAsc("u_level");
        this.sysOrgRoleEntityService.page(page, queryWrapper);
        long count = this.sysOrgRoleEntityService.count(queryWrapper);
        return R.ok(new PageResult<SysOrgRoleEntity>(count, page.getRecords()));
    }

}

